package com.spzx.product.controller;

import com.spzx.common.core.domain.R;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.service.IProductSkuService;
import com.spzx.product.api.domain.ProductSkuVo;
import com.spzx.product.vo.SkuPriceVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品sku 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-02-19
 */
@RestController
@RequestMapping("/productSku")
public class ProductSkuController extends BaseController {
    @Autowired
    private IProductSkuService productSkuService;

    @InnerAuth  //系统内部调用接口限制，不允许外部直接调用，即使携带要求内部调用请求头，经过网关会会清除掉
    @Operation(summary = "获取商品SKU详情")
    @GetMapping("/getProductSku/{skuId}")
    public R<ProductSkuVo> getProductSku(
            @Parameter(description = "skuId")
            @PathVariable("skuId") Long skuId) {
        ProductSku sku = productSkuService.getById(skuId);
        ProductSkuVo productSkuVo = new ProductSkuVo();
        BeanUtils.copyProperties(sku, productSkuVo);
        return R.ok(productSkuVo);
    }

    /**
     * 根据单个SKUID查询商品价格
     *
     * @param skuId
     * @return
     */
    @InnerAuth
    @Operation(summary = "获取商品sku最新价格信息")
    @GetMapping(value = "/getSkuPrice/{skuId}")
    public R<SkuPriceVo> getSkuPrice(@PathVariable("skuId") Long skuId) {
        return R.ok(productSkuService.getSkuPrice(skuId));
    }


    @InnerAuth
    @Operation(summary = "批量获取商品sku最新价格信息")
    @PostMapping(value = "/getSkuPriceList")
    public R<List<SkuPriceVo>> getSkuPriceList(@RequestBody List<Long> skuIdList) {
        List<SkuPriceVo> list = productSkuService.getSkuPriceList(skuIdList);
        return R.ok(list);
    }




}
